package com.lrkj.payfee.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.payfee.domain.Receipt;
import com.lrkj.payfee.service.IReceiptService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 收款单Controller
 *
 * @author yajun_ren
 * @date 2021-08-06
 */
@RestController
@RequestMapping("/payfee/receipt")
public class ReceiptController extends BaseController
{
    @Autowired
    private IReceiptService receiptService;

    /**
     * 查询收款单列表
     */
    @ApiOperation(value = "查询收款单列表", notes = "查询收款单列表")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(Receipt receipt)
    {
        startPage();
        this.changeParameter(receipt.getParams());
        List<Receipt> list = receiptService.selectReceiptList(receipt);
        return getDataTable(list);
    }

    /**
     * 导出收款单列表
     */
	@ApiOperation(value = "导出收款单列表", notes = "导出收款单列表")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:export')")
    @Log(title = "收款单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Receipt receipt)
    {
        List<Receipt> list = receiptService.selectReceiptList(receipt);
        ExcelUtil<Receipt> util = new ExcelUtil<Receipt>(Receipt.class);
        return util.exportExcel(list, "收款单数据");
    }

    /**
     * 获取收款单详细信息
     */
	@ApiOperation(value = "获取收款单详细信息", notes = "获取收款单详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:query')")
    @GetMapping(value = "/{receiptId}")
    public AjaxResult getInfo(@PathVariable("receiptId") String receiptId)
    {
        return AjaxResult.success(receiptService.selectReceiptById(receiptId));
    }

    /**
     * 新增收款单
     */
	  @ApiOperation(value = "新增收款单", notes = "新增收款单")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:add')")
    @Log(title = "收款单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Receipt receipt)
    {
        return toAjax(receiptService.insertReceipt(receipt));
    }

    /**
     * 修改收款单
     */
	 @ApiOperation(value = "修改收款单", notes = "修改收款单")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:edit')")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Receipt receipt)
    {
        return toAjax(receiptService.updateReceipt(receipt));
    }

    /**
     * 删除收款单
     */
    @ApiOperation(value = "删除收款单", notes = "删除收款单")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:remove')")
    @Log(title = "收款单", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteReceipt/{receiptIds}")
    public AjaxResult deleteReceipt(@PathVariable String[] receiptIds)
    {
        return toAjax(receiptService.deleteReceiptByIds(receiptIds));
    }

    /**
     * 收款单作废
     */
    @ApiOperation(value = "收款单作废", notes = "收款单作废")
    @PreAuthorize("@ss.hasPermi('payfee:receipt:nullify')")
    @Log(title = "收款单", businessType = BusinessType.DELETE)
    @DeleteMapping("/nullify/{receiptIds}")
    public AjaxResult nullify(@PathVariable String[] receiptIds)
    {
        return toAjax(receiptService.nullify(receiptIds));
    }


}
